package 蓝桥真题;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class 迷宫1 {
       static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       static char[][]g=new char[20][20];
       static boolean st[]=new boolean[200];
       static int dix[]={-1,1,0,0},diy[]={0,0,-1,1},res;
       static void find(int x,int y){
    	      while(true){
    	    	   int t=11*x+y;
    	    	   if(st[t])return;
    	    	   st[t]=true;
    	    	   char next=g[x][y];
    	    	   if(next=='\u0000'){
    	    		   res++;
    	    		   return;
    	    	   }
    	    	   else if(next=='U'){
    	    		    x=x+dix[0];y=y+diy[0];
    	    	   }else if(next=='D'){
    	    		    x=x+dix[1];y=y+diy[1];
    	    	   }else if(next=='L'){
    	    		    x=x+dix[2];y=y+diy[2];
    	    	   }else{
    	    		    x=x+dix[3];y=y+diy[3];
    	    	   }
    	      }
       }
       public static void main(String[] args) throws IOException {
		      for(int i=1;i<=10;i++){
		    	  br.read(g[i],1,10);
		    	  br.readLine();
		      }
		      for(int i=1;i<=10;i++)
		    	  for(int j=1;j<=10;j++){
		    		  Arrays.fill(st,false);
		    		  find(i,j);
		    	  }
		      System.out.print(res);
	}
}
